
module.exports = {
  pageInfo() {
    return {
      page: this.intVal('p', 1),
      pageSize: 20
    };
  },
  param(field, defaultValue) {
    const v = this.post(field) || this.get(field);
    if (v === undefined) {
      return defaultValue;
    }
    return v;
  },
  trimValue(field, defaultValue = '') {
    return this.param(field, defaultValue).toString().trim();
  },
  strValue(field, defaultValue = '') {
    return this.trimValue(field, defaultValue);
  },
  strVal(field, defaultValue = '') {
    return this.trimValue(field, defaultValue);
  },
  intVal(field, defaultValue) {
    return parseInt(this.param(field, defaultValue));
  },
  doubleVal(field, defaultValue) {
    return parseFloat(this.param(field, defaultValue));
  },
  getUser() {
    const token = this.ctx.header['user-token'];
    return think.userUtil.getUser(token);
  },
  getUserId() {
    const user = this.getUser();
    return user.id;
  }
};
